import re


class Dchind:
    def __init__(self, inse):
        self.inse = inse
        self.de1 =self.de2 = self.de3 = self.de4 = self.de5 = self.de6 = self.de7 = self.de8 = self.de9 =  self.dex =self.dey  = 0
        self.guige=''
        self.fenlei=''
    def select(self):

        x = re.split("\d*米$|一只|一套|\d*个$|\d*根$|\d*只$|\d*套$|\d*台$|\d*芯$|\d*D$|\d*平方米$|\d*平米$|\d*卷$|\d*次$", self.inse)[0]

        info = re.findall(
            "使用|整理|线路整理|电源线|接地|地锚|电池|光缆|-|电缆|钢绞线|钢缆|电杆|井|子管|pe|PE|pvc|PVC|钢管|出土管|路面|绿化|人行道|熔接|台班|用车|用工|分线|分纤|交接箱|光站|放大器|分支|分配|缆桥|光机|电源箱",
            self.inse)[0]
        self.fenlei=info
        if info in ("使用"):
            self.de1 = "Z"
            self.fenlei=""
        elif info in ("整理"):self.de1 = "A"
        elif info in ("回抽"):self.de1 = "B"
        elif info in ("电源线"):self.de1 = "C"
        elif info in ("接地"):self.de1 = "D"
        elif info in ("地锚"):self.de1 = "E"
        elif info in ("电池"):self.de1 = "F"
        elif info in ("光缆"):self.de1 = 'G'
        elif info in ("电缆","-"):self.de1 = 'H'
        elif info in ("钢绞线","钢缆"):self.de1 = 'I'
        elif info in ("电杆"):
            self.de1 = 'J'
            self.fenlei = ""
        elif info in ("井"): self.de1 = 'K'
        elif info in ("子管"): self.de1 = 'L'
        elif info in ("pe","PE"):self.de1 = 'M'
        elif info in ("pvc","PVC"):self.de1 = 'N'
        elif info in ("钢管"):self.de1 = 'O'
        elif info in ("出土管"):self.de1 = 'P'
        elif info in ("路面"): self.de1 = 'Q'
        elif info in ("绿化"): self.de1 = 'R'
        elif info in ("人行道"):self.de1 = 'S'
        elif info in ("熔接"):self.de1 = 'T'
        elif info in ("台班"):self.de1 = 'U'
        elif info in ("用车"):self.de1 = 'V'
        elif info in ("用工"):self.de1 = 'W'
        elif info in ("分线","分纤"):self.de1 = 'X'
        elif info in ("交接箱"):self.de1 = 'Y'
        elif info in ("光站"):self.de1 = 'a'
        elif info in ("放大器"):self.de1 = 'b'
        elif info in ("分支","分配"):self.de1 = 'c'
        elif info in ("缆桥"):self.de1 = 'd'
        elif info in ("光机"):self.de1 = 'e'
        elif info in ("电源箱"):self.de1 = 'f'



        try:
            sel = re.findall("拆|拆除|敷|铺|新|重建|重|修复|更换|换|安|安装|回抽", self.inse)[0]
            if sel in("拆|拆除"):self.de2=1
            elif sel in("新|敷|铺|安|安装"):self.de2=2
            elif sel in("重建|重"):self.de2=3
            elif sel in("修复|换|更换"):self.de2=4
            elif sel in ("回抽"):
                self.de2 = 5
        except:self.de2=0

        try:
            sel = re.findall("\d*D接线包|\d*D包|\d*[D芯]|扎线|扎带|防水胶带|防水胶布|胶带|胶布", self.inse)[0]
            if sel in ("4D|4芯"):                self.de3 = 1
            elif sel in ("8D|8芯"):                self.de3 = 2
            elif sel in ("24D|24芯"):                self.de3 = 3
            elif sel in ("48D|48芯"):                self.de3 = 4
            elif sel in ("96D|96芯"):                self.de3 = 5
            elif sel in ("144D|144芯"):                self.de3 = 6
            elif sel in ("288D|288芯"):                self.de3 = 7
            elif sel in("12D包|12D接线包"):self.de3="A"
            elif sel in("24D包|24D接线包"):self.de3="B"
            elif sel in("48D包|48D接线包"):self.de3="C"
            elif sel in("96D包|96D接线包"):self.de3="D"
            elif sel in("144D包|48D接线包"):self.de3="E"
            elif sel in("扎线|扎带"):self.de3="E"
            elif sel in("防水胶带|防水胶布|胶带|胶布"):self.de3="F"
            self.guige = sel
        except:
            self.de3 = 0




        try:
            sel = re.findall("-7|-9|-12|1孔|一孔|2孔|两孔|二孔|3孔|三孔|4孔|四孔|7米电杆|七米电杆|8米电杆|八米电杆|9米电杆|九米电杆", self.inse)[0]
            self.guige=sel
            if sel in ("-7",):
                self.de4 = 1
                self.fenlei = "电缆"
            elif sel in ("-9",):
                self.de4 = 2
                self.fenlei = "电缆"
            elif sel in ("-12",):
                self.de4 = 3
                self.fenlei = "电缆"
            elif sel in ("一孔", "1孔"):self.de4 = 4
            elif sel in ("2孔", "两孔","2孔"):self.de4 = 5
            elif sel in ("3孔", "三孔"):self.de4 = 6
            elif sel in ("4孔", "四孔"):self.de4 = 7
            elif sel in ("7米电杆","七米电杆"):self.de4 = 8
            elif sel in ("8米电杆", "八米电杆"):self.de4 = 9
            elif sel in ("9米电杆", "九米电杆"):self.de4 = "A"
        except:self.de4 = 0


        try:
            sel = re.findall("架空|管道|楼内|钢纤维|复合|挂壁|壁挂|落地", self.inse)[0]
            if sel in("架空"):self.de5=1
            elif sel in("管道"):self.de5=2
            elif sel in("楼内"):self.de5=3
            elif sel in("钢纤维"):self.de5=4
            elif sel in("复合"):self.de5=5
            elif sel in("挂壁|壁挂"):self.de5=6
            elif sel in("落地"):self.de5=7
        except:self.de5=0



        try:
            sel = re.findall("不含|基|底座", self.inse)[0]
            if sel in("不含"):self.de6=0
            elif sel in("基","底座"):self.de6=1
        except:self.de6=0


        try:
            sel = re.findall("500x|600x|700x|730x|900x|1000x|1200x|1500x", self.inse)[0]

            if sel in("500x"):self.de7=1
            elif sel in("600x"):self.de7=2
            elif sel in("700x"):self.de7=3
            elif sel in("730x"):self.de7=4
            elif sel in("900x"):self.de7=5
            elif sel in("1000x"):self.de7=6
            elif sel in("1200x"):self.de7=7
            elif sel in("1500x"):self.de7=8
        except:self.de7=0

        try:
            sel = re.findall("φ\d*", self.inse)[0]
            self.guige = self.guige + sel
            if sel in("φ25"):self.de8=1
            elif sel in("φ32"):self.de8=2
            elif sel in("φ40"):self.de8=3
            elif sel in("φ50"):self.de8=4
            elif sel in("φ75"):self.de8=5
            elif sel in("φ89"):self.de8=6
            elif sel in("φ100"):self.de8=7
            elif sel in("φ102"):self.de8=8
            elif sel in("φ110"):self.de8=9
        except:self.de8=0


        try:
            sel = re.findall("柏油|混凝土|砂石|钢纤维|不含|基|底座", self.inse)[0]
            if sel in("柏油"):self.de9=1
            elif sel in("混凝土"):self.de9=2
            elif sel in("砂石"):self.de9=3
        except:self.de9=0


        try:
            sel = re.findall("箱", self.inse)[0]
            self.fenlei=self.fenlei+"箱"
            if sel in("箱"):self.dex=1
        except:self.dex=0

        try:
            sel = re.findall("只$|套$|D$|芯$", self.inse)[0]
            if sel in("只"):self.dey=1
            elif sel in ("套"): self.dey = 2
            elif sel in ("D|芯"):
                sel1 = re.findall("\d*D$|\d*芯$", self.inse)[0]
                sel2=int(re.split("[D芯]",sel1)[0])
                if sel2<97:self.dey=3
                elif sel2>97:self.dey=4
        except:self.dey=0



    def theUnit(self):
        # try:
        xx = \
        re.findall("\d*米$|一只|一套|\d*个$|\d*根$|\d*只$|\d*套$|\d*台$|\d*芯$|\d*D$|\d*平方米$|\d*平米$|\d*卷$|\d*次$", self.inse)[
            0]
        yy = re.split("米|只|个|根|套|台|芯|平方米|平米|D|卷|次", xx)[0]
        if yy == "一":
            return 1
        else:
            return int(yy)

    def theUnitDW(self):
        xx =re.findall("米$|只|套|个$|根$|只$|套$|台$|芯$|D$|平方米$|平米$|卷$|次$", self.inse)[0]
        return xx

    def setit(self):
        self.select()

        denum = str(self.de1) + str(self.de2) + str(self.de3) + str(self.de4) + str(self.de5) + str(self.de6) + str(
            self.de7) + str(self.de8)+ str(self.de9)+ str(self.dex) + str(self.dey)

        return denum
